﻿using System;
using UnityEngine;
using UnityEngine.Serialization;
using Whoot.DI.Context.Internal;

namespace Whoot.DI.Context
{
    public class GameObjectContext : MonoContext
    {
        [FormerlySerializedAs("parentContext")] [SerializeField] private MonoContext parentMonoContext;

        private readonly Lazy<IGameObjectContextService> _serviceLazy =
            new Lazy<IGameObjectContextService>(MonoContextContainer.Resolve<IGameObjectContextService>);

        internal override IContext ParentContext =>
            _serviceLazy.Value.GetGameObjectContextOrDefault(this, parentMonoContext);
        
        protected override void OnDestroy()
        {
            base.OnDestroy();
            parentMonoContext = null;
        }
        
    }
}